﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sponsorship.Domain.Memberships;
using Sponsorship.Domain.Payments;

namespace Sponsorship.Domain.Sponsors
{
    using System;
    using System.Diagnostics;
    using CommonDomain;
    using CommonDomain.Core;

        /// <summary>
        /// Represents a <see cref="Sponsor"/> in the Sponsorship domain. A <see cref="Sponsor"/> can have multiple <see cref="Membership"/> and <see cref="Sponsorship"/> and can be associated to <see cref="Payment" />.
        /// </summary>
        public class Sponsor : RelaxedAggregateBase
        {
            public Sponsor(Guid id, string firstName, string lastName, BankInformation bankInformation, Address address, string eMail, string telephoneNumber, string comment)
                : this(id, null)
            {
                //Business logic
                if (id == Guid.Empty)
                    throw new ArgumentException("Id must not be empty.", "id");

                RaiseEvent(new SponsorEntered(id, firstName, lastName, bankInformation, address, eMail, telephoneNumber, comment));
            }

            // Infrastructure constructor used by AggregateFactory
            private Sponsor(Guid id, IMemento snapshot)
            {
                if (snapshot != null)
                    throw new NotSupportedException("This class does not support snapshots.");
                Id = id;
            }

            protected override IMemento GetSnapshot()
            {
                throw new NotSupportedException("This class does not support snapshots.");
            }

            public void Change (string firstName, string lastName, BankInformation bankInformation, Address address, string eMail, string telephoneNumber, string comment)
            {
                RaiseEvent(new SponsorChanged(Id, firstName, lastName, bankInformation, address, eMail, telephoneNumber, comment));                
            }

            public void Delete()
            {
                RaiseEvent(new SponsorDeleted(Id));                
            }
        }
}
